package la.iok.hzsvn.lewin.movie.cloud.model;

import java.util.Objects;

public class PhoneCode {
    /**
     * 验证码
     */
    private String code;
    /**
     * 手机号
     */
    private String phoneNumber;
    /**
     * 客户端设备所在的组织
     */
    private Long orgUnitId;
    /**
     * 操作类型。1为注册,2为登录
     */
    private int operation;
    /**
     * 有效时长,单位秒，超过这个时间验证码就失效
     */
    private int expiresIn;

    public PhoneCode() {
    }

    public PhoneCode(String code) {
        this.code = code;
        this.expiresIn = 120;
    }

    public PhoneCode(String code, int expireIn) {
        this.code = code;
        this.expiresIn = expireIn;
    }

    public PhoneCode(String code, String phoneNumber,int operation) {
        this.code = code;
        this.phoneNumber = phoneNumber;
        this.operation = operation;
        this.expiresIn = 120;
    }

    public PhoneCode(String code, String phoneNumber, int operation, int expireIn) {
        this.code = code;
        this.phoneNumber = phoneNumber;
        this.operation = operation;
        this.expiresIn = expireIn;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public Long getOrgUnitId() {
        return orgUnitId;
    }

    public void setOrgUnitId(Long orgUnitId) {
        this.orgUnitId = orgUnitId;
    }

    public int getOperation() {
        return operation;
    }

    public String operationStr(){
        if(operation == PhoneCodeParam.OPERATION_REG){
            return "注册";
        }else if(operation == PhoneCodeParam.OPERATION_LOGIN){
            return "登录";
        }else if(operation == PhoneCodeParam.OPERATION_MODIFY_ACCOUNT){
            return "账号修改";
        }else if(operation == PhoneCodeParam.OPERATION_MODIFY_PASSWORD) {
            return "密码修改";
        }
        return "未知";
    }

    public void setOperation(int operation) {
        this.operation = operation;
    }

    public int getExpiresIn() {
        return expiresIn;
    }

    public String expiresMinuteStr(){
        int minutes = expiresIn / 60;
        return String.valueOf(minutes);
    }

    public void setExpiresIn(int expiresIn) {
        this.expiresIn = expiresIn;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        PhoneCode phoneCode = (PhoneCode) o;
        return operation == phoneCode.operation && expiresIn == phoneCode.expiresIn && Objects.equals(code, phoneCode.code) && Objects.equals(phoneNumber, phoneCode.phoneNumber) && Objects.equals(orgUnitId, phoneCode.orgUnitId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, phoneNumber, orgUnitId, operation, expiresIn);
    }
}
